﻿using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
using System.IO;

namespace edu.und.crc.clients.chemistry.macrodox
{
    static class Mutate
    {
        public static void beginMutation(ref Sbir sbir)
        {
            Console.Clear();
            Console.Write("Input path to the Residue Replacement file (ie. mutate.dat):\n> ");
            string ffPath = Console.ReadLine();

            if (Directory.Exists(ffPath))
            {
                Console.WriteLine("The path you entered is not a file.\n\nPress 'Enter' to return to main menu...");
                Console.ReadLine();
                return;
            }
            else if (!File.Exists(ffPath))
            {
                Console.WriteLine("The file '{0}' was not found!\n\nPress 'Enter' to return to main menu...", ffPath);
                Console.ReadLine();
                return;
            }

            MutateData md = new MutateData();
            try
            {
                md.initData(ffPath.Trim());
            }
            catch (Exception e)
            {
                Console.Clear();
                Console.WriteLine("File Not Found");
                Console.WriteLine("\nPress 'Enter' to return to the main menu...");
            }

            Console.Clear();
            Console.Write("Input path to the Search Parameter file:\n> ");
            string repPath = Console.ReadLine();

            if (Directory.Exists(repPath))
            {
                Console.WriteLine("The path you entered is not a file.\n\nPress 'Enter' to return to main menu...");
                Console.ReadLine();
                return;
            }
            else if (!File.Exists(repPath))
            {
                Console.WriteLine("The file '{0}' was not found!\n\nPress 'Enter' to return to main menu...", repPath);
                Console.ReadLine();
                return;
            }

            ReplaceData rd = new ReplaceData();
            try
            {
                rd.readValues(repPath.Trim());
            }
            catch (Exception e)
            {
                Console.Clear();
                Console.WriteLine("File Not Found");
                Console.WriteLine("\nPress 'Enter' to return to the main menu...");
            }

            //Eventually, I would expect the PDB or Macrodox file path
            //to be passed to the beginMutation method. But right now
            //we're asking the user to input this path at the command
            //line.
            Console.Clear();
            Console.Write("Input path to PDB/Macrodox file:\n> ");
            string mdxPath = Console.ReadLine();

            if (Directory.Exists(mdxPath))
            {
                Console.WriteLine("The path you entered is not a file.\n\nPress 'Enter' to return to main menu...");
                Console.ReadLine();
                return;
            }
            else if (!File.Exists(mdxPath))
            {
                Console.WriteLine("The file '{0}' was not found!\n\nPress 'Enter' to return to main menu...", mdxPath);
                Console.ReadLine();
                return;
            }

            DataBlock db = new DataBlock();
            db.setMD(ref md);
            db.setRP(ref rd);
            try
            {
                db.readFile(mdxPath);
            }
            catch (Exception e)
            {
                Console.Clear();
                Console.WriteLine("File Not Found");
                Console.WriteLine("\nPress 'Enter' to return to the main menu...");
            }
            Console.ReadLine();
            return;
        }
    }
}
